/*
	Project:FFmpeg Media Source for Windows Media Foundation
	File:legacy_win32.cpp

	Creator:ShanYe (2014-06-13)
	Last Change:ShanYe (2014-06-16)
	Rev:1.0.0
*/

#include "stdafx.h"
#include "legacy_win32.h"

DECLSPEC_NOINLINE BOOL GetFileSizeEx_WinRT(HANDLE hFile,PLARGE_INTEGER lpFileSize)
{
	FILE_STANDARD_INFO stdInfo = {};
	BOOL bResult = GetFileInformationByHandleEx(hFile,FileStandardInfo,&stdInfo,sizeof FILE_STANDARD_INFO);
	lpFileSize->QuadPart = stdInfo.EndOfFile.QuadPart;
	return bResult;
}

DECLSPEC_NOINLINE DWORD SetFilePointer_WinRT(HANDLE hFile,LONG lDistanceToMove,PLONG lpDistanceToMoveHigh,DWORD dwMoveMethod)
{
	LARGE_INTEGER li;
	li.LowPart = lDistanceToMove;
	li.HighPart = 0;
	LARGE_INTEGER liNew;
	liNew.QuadPart = 0;
	SetFilePointerEx(hFile,li,&liNew,dwMoveMethod);
	return liNew.LowPart;
}

DECLSPEC_NOINLINE HANDLE CreateFile_WinRT(LPCWSTR lpFileName,DWORD dwDesiredAccess,DWORD dwShareMode,LPSECURITY_ATTRIBUTES lpSecurityAttributes,DWORD dwCreationDisposition,DWORD dwFlagsAndAttributes,HANDLE hTemplateFile)
{
	return CreateFile2(lpFileName,dwDesiredAccess,dwShareMode,dwCreationDisposition,NULL);
}

DECLSPEC_NOINLINE HANDLE CreateEvent_WinRT(LPSECURITY_ATTRIBUTES lpEventAttributes,BOOL bManualReset,BOOL bInitialState,LPCWSTR lpName)
{
	DWORD dwFlags = 0;
	if (bManualReset)
		dwFlags = CREATE_EVENT_MANUAL_RESET;
	if (bInitialState)
		dwFlags |= CREATE_EVENT_INITIAL_SET;
	return CreateEventExW(lpEventAttributes,lpName,dwFlags,EVENT_ALL_ACCESS);
}

DECLSPEC_NOINLINE HANDLE CreateMutex_WinRT(LPSECURITY_ATTRIBUTES lpMutexAttributes,BOOL bInitialOwner,LPCWSTR lpName)
{
	DWORD dwFlags = bInitialOwner ? CREATE_MUTEX_INITIAL_OWNER:0;
	return CreateMutexExW(lpMutexAttributes,lpName,dwFlags,MUTEX_ALL_ACCESS);
}

DECLSPEC_NOINLINE HANDLE CreateSemaphore_WinRT(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,LONG lInitialCount,LONG lMaximumCount,LPCWSTR lpName,DWORD dwFlags,DWORD dwDesiredAccess)
{
	return CreateSemaphoreExW(lpSemaphoreAttributes,lInitialCount,lMaximumCount,lpName,0,SEMAPHORE_ALL_ACCESS);
}